home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland Pascal with Objects 7.0 / RWDEMOS.ZIP / BITBNAPP.PAS next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  2.7 KB  |  117 lines

  1. {************************************************}
  2. {                                                }
  3. {   Resource Workshop Demo program               }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. { This program uses a DLL that implements custom controls.
  9.   Make sure you build the DLL (BITBTN.PAS) before running
  10.   this program. }
  11.  
  12. program BitBnApp;
  13.  
  14. {$R BitBnApp.RES}
  15.  
  16. uses WinTypes, WinProcs, Win31, Objects, OWindows, ODialogs;
  17.  
  18. const
  19.   DLLName = 'BITBTN.DLL';
  20.  
  21. const
  22.   em_DLLNotFound = 1;
  23.  
  24. type
  25.   PBitWindow = ^TBitWindow;
  26.   TBitWindow = object(TDlgWindow)
  27.     procedure Yes(var Msg: TMessage);
  28.       virtual id_First + id_Yes;
  29.     procedure No(var Msg: TMessage);
  30.       virtual id_First + id_No;
  31.     procedure Ok(var Msg: TMessage);
  32.       virtual id_First + id_OK;
  33.     procedure Cancel(var Msg: TMessage);
  34.       virtual id_First + id_Cancel;
  35.   end;
  36.  
  37.   PBitApp = ^TBitApp;
  38.   TBitApp = object(TApplication)
  39.     Lib: THandle;
  40.     constructor Init(AName: PChar);
  41.     destructor Done; virtual;
  42.     procedure InitMainWindow; virtual;
  43.     procedure Error(ErrorCode: Integer); virtual;
  44.   end;
  45.  
  46. { TBitApp }
  47.  
  48. constructor TBitApp.Init(AName: PChar);
  49. begin
  50.   { Tell Windows not to display a 'DLL not found' error
  51.     dialog if the LoadLibrary function fails.  We'll handle
  52.     the error and inform the user ourselves.
  53.     Note that even though this SEM_ constant is defined and
  54.     documented only in Windows 3.1, it actually works in
  55.     Windows 3.0 as well... }
  56.   SetErrorMode(SEM_NoOpenFileErrorBox);
  57.   Lib := LoadLibrary(DLLName);
  58.   if Lib < 32 then
  59.     Status := em_DLLNotFound
  60.   else
  61.     TApplication.Init(AName);
  62. end;
  63.  
  64. destructor TBitApp.Done;
  65. begin
  66.   TApplication.Done;
  67.   FreeLibrary(Lib);
  68. end;
  69.  
  70. procedure TBitApp.InitMainWindow;
  71. begin
  72.   MainWindow := New(PBitWindow, Init(nil, MakeIntResource(100)));
  73. end;
  74.  
  75. procedure TBitApp.Error(ErrorCode: Integer);
  76. begin
  77.   case ErrorCode of
  78.     em_DLLNotFound:
  79.       MessageBox(0, DLLName + ' not found. Please compile BITBTN.PAS ' +
  80.         'before executing this application.', 'Fatal error',
  81.         mb_Ok or mb_IconStop);
  82.   else
  83.     TApplication.Error(ErrorCode);
  84.   end;
  85. end;
  86.  
  87. { TBitWindow }
  88.  
  89. procedure TBitWindow.Yes(var Msg: TMessage);
  90. begin
  91.   CloseWindow;
  92. end;
  93.  
  94. procedure TBitWindow.No(var Msg: TMessage);
  95. begin
  96.   CloseWindow;
  97. end;
  98.  
  99. procedure TBitWindow.Ok(var Msg: TMessage);
  100. begin
  101.   CloseWindow;
  102. end;
  103.  
  104. procedure TBitWindow.Cancel(var Msg: TMessage);
  105. begin
  106.   CloseWindow;
  107. end;
  108.  
  109. var
  110.   App: TBitApp;
  111.  
  112. begin
  113.   App.Init('TBITBTN.DDL Demo');
  114.   App.Run;
  115.   App.Done;
  116. end.
  117.